//
//  BKMain_ClassifyTitleCell.m
//  bestkeep
//
//  Created by utouu666 on 17/2/14.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKMain_ClassifyTitleCell.h"
#import "BKMainCommon.h"
#import "UIButton+XN.h"

@interface BKMain_ClassifyTitleCell()
@property(nonatomic,strong)CategoryIconModel *model;
@end

@implementation BKMain_ClassifyTitleCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initialize];
    }
    return self;
}

-(void)initialize{
    
    _classifyTitle = [[UILabel alloc]init];
    _classifyTitle.textColor = RGBACOLOR(64, 64, 64, 1);
    _classifyTitle.font = [Common systemFontOfSize:15];
    [self addSubview:_classifyTitle];
    CGPoint centerP = self.center;
    [_classifyTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(@(centerP.x-20));
        make.centerY.equalTo(self.mas_centerY);
    }];
    UIView *line = [UIView new];
    line.backgroundColor = RGB(242, 242, 242);
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.height.equalTo(@1);
    }];
    
    _classifyImageView = [[UIImageView alloc]init];
    [self addSubview:_classifyImageView];
    [_classifyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.classifyTitle.mas_left).offset(-10);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.width.equalTo(@(18));
        make.height.equalTo(@(19));
    }];
    
//    _rightImageIcon = [[UIImageView alloc]init];
//    UIImage *image = [UIImage imageNamed:@"BKMain_jiantou"];
//    _rightImageIcon.image = [UIImage imageNamed:@"BKMain_jiantou"];
//    [self addSubview:_rightImageIcon];
//    [_rightImageIcon mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(_classifyTitle.mas_right).offset(7);
//        make.centerY.equalTo(self.mas_centerY);
//        make.width.equalTo(@(image.size.width));
//        make.height.equalTo(@(image.size.height));
//    }];
    
        
}

+(CGFloat)computeHeight:(id)data{
    if(!data || ![data isKindOfClass:[NSArray class]]) {
        return 0;
    }
    return 40;
}

- (void)fillData:(id)data{
    if (!data) {
        return;
    }
    NSDictionary *data_dic = data;
    if (data_dic.allKeys.count == 3) {
        _classifyTitle.text = data_dic[@"categoryName"];
        [_classifyImageView load:data_dic[@"smallIconImg"] placeholderImage:[UIImage imageNamed:@"BKFeatured_newGoods"]];
        return;
    }
    _model = [[CategoryIconModel alloc]init];
    [_model setValuesForKeysWithDictionary:data];
    _classifyTitle.text = _model.name;
    [_classifyImageView load:_model.iconImg placeholderImage:[UIImage imageNamed:@"BKFeatured_newGoods"]];
    
}




@end
